home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 5.7 KB | 235 lines | [TEXT/ttxt] |
- --<<<
-
- in module WebBrowser
-
- class WebBrowser ()
- instance variables
- topWin
- scroller
- group
- currentURL
- displayer
- forwardList
- backwardList
- reloadButton
- backButton
- forwardButton
- status
- applets : (new Array)
- urlField
- openFileButton
- gotoButton
- end
-
-
- method makewebbutton self {object Webbrowser} label x y win fun -> (
- local pb := new TextButton text: label
- pb.x := x
- pb.y := y
- append win pb
- pb.activateAction := (data button -> fun self)
- pb
- )
-
- method gotoURLCallback self {object Webbrowser} ->
- followlink self (new url string: self.urlfield.text)
-
-
- method openFile self {object Webbrowser} -> (
- local o := new openpanel
- openfilepanel o
- if o.validreply do (
- local u := "file://" as string
- for x in o.filename do (
- addmany u "/"
- addmany u x
- )
- followlink self (new url string: u)
- )
- )
-
- method init self {object WebBrowser} #rest args #key url: -> (
- apply nextMethod self args
- -- self.topWin := new window boundary: (new rect x1: 50 y1: 50 x2: 600 y2: 700) name: "HotSX"
- self.topWin := new window boundary: (new rect x1: 50 y1: 50 x2: 600 y2: 600) name: "HotSX"
- local bc := new actuatorcontroller space: self.topWin
- bc.wholespace := true
- self.backButton := makeWebButton self "Back" 10 10 self.topWin goBack
- self.reloadButton := makeWebButton self "reload" 100 10 self.topWin reload
- self.forwardButton := makeWebButton self "forward" 200 10 self.topWin goForward
- self.openFileButton := makeWebButton self "open file" 300 10 self.topWin openFile
-
- local headerHeight := 50
- local footerHeight := 20
- local spacing := 20
-
- local gotoY := spacing + self.openFileButton.height
-
- self.gotoButton := makeWebButton self "Goto:" 10 gotoY self.topWin gotoURLCallback
-
- headerHeight := headerHeight + self.gotoButton.height + spacing
-
- self.urlField := new SmallTextEdit
- self.urlField.width := 400
-
- self.urlField.x := 10 + self.gotoButton.width + spacing
- self.urlField.y := gotoY
-
- append self.topWin self.urlField
-
- local scrollerHeight := ( self.topwin.height - headerHeight - footerHeight)
- self.scroller := new ScrollingPresenter \
- vertScrollbar: (new SimpleScrollBar \
- height: scrollerHeight) \
- fill:WhiteBrush \
- stationary:true \
- stroke: blackbrush \
- boundary: (new rect x2: self.topwin.width \
- y2: scrollerHeight)
- self.scroller.y := headerHeight
- append self.topwin self.scroller
- self.group := new groupPresenter
- self.scroller.targetPresenter := self.group
-
- show self.topWin
- self.forwardList := new LinkedList
- self.backwardList := new LinkedList
-
- self.status := new textPresenter target: "hello there" \
- boundary: (new rect x2: self.topwin.width \
- y2: footerHeight)
- self.status.y := self.topwin.height - footerHeight
- append self.topwin self.status
- if url != unsupplied then
- gotoURL self url
- else
- updateButtons self
- )
-
- method updateButtons self {object WebBrowser} -> (
- self.reloadButton.enabled := self.currentURL != undefined
- self.backButton.enabled := not (isempty self.backwardList)
- self.forwardButton.enabled := not (isempty self.forwardList)
- if self.currentURL != undefined do
- self.urlField.text := self.currentURL.string
- )
-
- method setStatus self {object WebBrowser} status ->
- self.status.target := status
-
- method gotoURL self {object WebBrowser} aurl -> (
- setstatus self "Downloading..."
- -- We can get some kind of error at this point
-
- if not (isakindof aurl url) do
- aurl := new url string: aurl
-
- local s := geturl WebAccessManager aurl
-
- -- Perhaps a transition would be nice!
-
- if (present WebPresentationManager s \
- callback: (ignore url -> followLink self url) \
- boundary: (new rect x2: ( self.topwin.width - self.scroller.vertScrollbar.width) \
- y2: self.topwin.height) \
- url: aurl \
- parent: self.group \
- browser: self)
- do (
-
- -- End of possible errors
-
- layout self.scroller
- self.currentURL := aurl
- updateButtons self
- setStatus self ""
- return true
- )
- setStatus self ""
- updateButtons self
- return false
- )
-
- method followLink self {object WebBrowser} url -> \
- doSomething self \
- (->
- local old := self.currentURL
- -- Used & otherwise the 'event dispatch queue' thread messed up
- if gotoURL self url do (
- if old != undefined do (
- prepend self.backwardList old
- emptyOut self.forwardList
- )
- )
- )
-
-
- method goBack self {object WebBrowser} -> \
- dosomething self \
- (->
- local n := pop self.BackwardList
- prepend self.forwardList self.currentURL
- gotoURL self n
- )
-
- method goForward self {object WebBrowser} -> \
- dosomething self \
- ( ->
- local n := pop self.forwardList
- prepend self.backwardList self.currentURL
- gotoURL self n
- )
-
- method reload self {object WebBrowser} -> \
- dosomething self (-> gotoURL self self.currentURL)
-
- -- We need a way of managing this
- -- We should just keep track of this thread and kill it
-
- method doSomething self {object WebBrowser} something -> \
- (
- guard
- something()
- catching
- Exception : (
- local s := new string
- format s throwtag throwarg
- setStatus self s
- caught undefined
- )
- end
- updateButtons self
- ) &
-
- method addApplet self {object WebBrowser} applet -> (
- append self.applets applet
- )
-
- method clearCurrent self {object WebBrowser} -> (
- -- Perhaps a transition would be nice!
- emptyOut self.group
- map self.applets (applet arg -> terminate applet) undefined
- emptyOut self.applets
- )
-
- function presentHTML stuff #rest args #key browser: -> (
- clearCurrent browser
- local displayer := apply new htmlDisplayer args
- stuff[2] | displayer.stream
- plug stuff[2]
- plug displayer
- return true
- )
-
- registerPresentMethod WebPresentationManager "text/html" presentHTML
-
- global theWebBrowser := undefined
-
- function startWebBrowser tc -> (
- if not (isdefined tcpstream) do process (new loader) "loadable/web"
- foreach tc load undefined
- theWebBrowser := new webbrowser
- )
-
- -->>>
-